"""OpenVDB BUILD file."""

load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_cc//cc:defs.bzl", "cc_library")

expand_template(
    name = "version",
    out = "openvdb/openvdb/version.h",
    substitutions = {
        "#cmakedefine OPENVDB_IMATH_VERSION": "",
        "#cmakedefine OPENVDB_USE_BLOSC": "",
        "#cmakedefine OPENVDB_USE_DELAYED_LOADING": "",
        "#cmakedefine OPENVDB_USE_EXPLICIT_INSTANTIATION": "",
        "#cmakedefine OPENVDB_USE_IMATH_HALF": "",
        "#cmakedefine OPENVDB_USE_ZLIB": "",
        "${OPENVDB_ABI_VERSION_NUMBER}": "11",
        "${OPENVDB_NAMESPACE_SUFFIX}": "",
        "${OPENVDB_PACKED_VERSION}": "0",
        "${OpenVDB_MAJOR_VERSION}": "11",
        "${OpenVDB_MINOR_VERSION}": "0",
        "${OpenVDB_PATCH_VERSION}": "0",
    },
    template = "openvdb/openvdb/version.h.in",
)

filegroup(
    name = "common_sources_nanovdb",
    srcs = glob([
        "nanovdb/nanovdb/*.h",
        "nanovdb/nanovdb/util/*.h",
        "nanovdb/nanovdb/util/**/*.h",
    ]),
)

filegroup(
    name = "common_sources_openvdb",
    srcs = glob([
        "openvdb/openvdb/*.cc",
        "openvdb/openvdb/io/*.cc",
        "openvdb/openvdb/math/*.cc",
        "openvdb/openvdb/points/*.cc",
        "openvdb/openvdb/util/*.cc",
    ]),
)

filegroup(
    name = "common_sources_openvdb_inc",
    srcs = glob([
        "openvdb/openvdb/math/*.h",
        "openvdb/openvdb/points/*.h",
        "openvdb/openvdb/points/impl/*.h",
        "openvdb/openvdb/io/*.h",
        "openvdb/openvdb/util/*.h",
        "openvdb/openvdb/tree/*.h",
        "openvdb/openvdb/tools/*.h",
        "openvdb/openvdb/thread/*.h",
        "openvdb/openvdb/*.h",
    ]),
)

cc_library(
    name = "nanovdb",
    srcs = [
        ":common_sources_nanovdb",
    ],
    includes = ["nanovdb"],
    linkopts = select({
        "@platforms//os:linux": ["-pthread"],
        "//conditions:default": [],
    }),
    linkstatic = True,
    visibility = ["//visibility:public"],
)

cc_library(
    name = "openvdb",
    srcs = [
        ":common_sources_openvdb",
    ],
    hdrs = [
        "openvdb/openvdb/version.h",
        ":common_sources_openvdb_inc",
    ],
    includes = [
        "openvdb",
        "openvdb/openvdb",
    ],
    linkopts = select({
        "@platforms//os:linux": ["-pthread"],
        "//conditions:default": [],
    }),
    linkstatic = True,
    visibility = ["//visibility:public"],
    deps = [
        "@boost.numeric_conversion",
        "@onetbb//:tbb",
    ],
)
